/**
 * $Revision: 1.0 $
 * $Author: Eric Yang $
 * $Date: Apr 17, 2009 8:17:43 PM $
 *
 * Author: Eric Yang
 * Date  : Apr 17, 2009 8:17:43 PM
 *
 */
package com.hgy.commonsale.core.listener;

/**
 * @author Eric Yang
 * @version 1.0
 */

import java.io.File;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import com.hgy.commonsale.webui.conf.ApplicationConfiguration;

/**
 * Created: 2007-3-19 Modified: 2007-3-19 Author: Keven Chen
 */
public class ApplicationSetupListener implements ServletContextListener {

	public void contextDestroyed(ServletContextEvent event) {
	}

	public void contextInitialized(ServletContextEvent event) {
		String uploadDir = ApplicationConfiguration.getProperty(ApplicationConfiguration.UPLOAD_DIR_KEY);
		String real_path = event.getServletContext().getRealPath(uploadDir);
		File file = new File(real_path);
		if (!file.exists() || file.isFile()) {
			file.mkdirs();
		}
		String separator = System.getProperty("file.separator");
		if (!real_path.endsWith(separator)) {
			real_path = real_path + separator;
		}
		ApplicationConfiguration.setProperty(ApplicationConfiguration.UPLOAD_DIR_KEY, real_path);
		ApplicationConfiguration.UPLOAD_DIR = real_path;
	}
}
